package multiarray;
import java.util.Arrays;
import java.util.Collection;

import junit.framework.Assert;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;



@RunWith(Parameterized.class)
public class MultiArrayParameterizedTest {

	int index;
	static int[] dimensionSizes = new int[]{2, 5, 7, 4, 3, 8};
	static int maxIndex = 2*5*7*4*3*8-1;
	static MultiArray multiArray;

	public MultiArrayParameterizedTest(int index) {
		super();
		this.index = index;
	}

	@Parameters
	public static Collection indices() {
		/*
		return new Iterator<Object[]>(){

			int indexCounter = 0;
			
			@Override
			public boolean hasNext() {
				if(indexCounter < maxIndex)
					return true;
				return false;
			}

			@Override
			public Object[] next() {
				int oldIndex = indexCounter;
				indexCounter++;
				return new Object[]{oldIndex};
			}

			@Override
			public void remove() {
			}
			
			
		};
		*/
		
		/*
		return Arrays.asList (new Object[][]{
				{},	
				{},
				{},
		}
		);
		*/
		
		return Arrays.asList(buildArrayOfIntegers(maxIndex));
	}

	@Test
	public void verifyIndexingAndExpansion() throws Exception{
		int[] positions = multiArray.getElementPositions(index);
		int reverseIndex = multiArray.getElementIndex(positions);
		Assert.assertEquals("expansion did not match indexing", index, reverseIndex);
	}

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		multiArray = new MultiArray(dimensionSizes);
	}
	
	public static Object[][] buildArrayOfIntegers(int index){
		Object[][] result = new Object[index][];
		for(int i = 0; i < index; i++){
			result[i] = new Object[]{i};
		}
		return result;
	}
	
}